package com.mlm.mlmapp.adapter.view;

import com.mlm.mlmapp.utils.CommonUtils;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.WindowManager;
import android.widget.ListView;

public class MyListView extends ListView {
	private int listViewHeight;
	private Context mContext;

	public MyListView(Context context) {
		super(context);
		this.mContext = context;
		LayoutInflater i = LayoutInflater.from(context);
		// this.setEmptyView(i.inflate(R.layout.book_dialog_no_item, null));
	}

	public MyListView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
		this.mContext = context;
	}

	public MyListView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		this.mContext = context;
	}

	private int getScreenHeight() {
		WindowManager wm = (WindowManager) mContext
				.getSystemService(Context.WINDOW_SERVICE);
		// DisplayMetrics metrics = new DisplayMetrics();
		// wm.getDefaultDisplay().getMetrics(metrics);
		// int height = metrics.heightPixels;// 屏幕的高dp
		return wm.getDefaultDisplay().getHeight();
		// return height;
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		// TODO Auto-generated method stub

		listViewHeight = getScreenHeight() - CommonUtils.dip2px(mContext, 200);
		// listViewHeight=CommonUtils.dip2px(mContext, getScreenHeight()-200);
		if (listViewHeight > -1) {
			heightMeasureSpec = MeasureSpec.makeMeasureSpec(listViewHeight,
					MeasureSpec.AT_MOST);
		}
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
	}

}
